﻿@model Mindfor.Web.Modules.System.RoutesModel
@{
	this.Layout = "~/Modules/Shared/_Admin.cshtml";
	PageTitle.AddViewTitle("Системные маршруты");	

	IEnumerable<RouteData> matches = Model.MatchRoutes;
	Route firstRoute = null;
	RouteData firstRouteData = null;
	if (matches != null && matches.Count() > 0)
	{
		firstRouteData = matches.FirstOrDefault();
		firstRoute = firstRouteData.Route as Route;
	}
}

<form method="get" action="@Url.Action("Routes")">
	<fieldset class="form">
		<legend>Проверка маршрута</legend>
		<label for="Route" class="inline">Ссылка:</label>
		@Html.TextBox("Route")
		<input type="submit" value="Проверить" />&nbsp;
		@Html.ActionLink("Отменить", "Routes")
		
		@if (matches != null) {
			<p>Подходящих маршрутов: <b>@matches.Count()</b></p>
			if (firstRoute != null) {
				<p>
					Активный маршрут: <b>@firstRoute.Url</b><br />
					@foreach (var kv in firstRouteData.Values) {
						@kv.Key<text> = </text>@kv.Value<br/>
					}
				</p>
			}
		}
	</fieldset>
</form>
	
<table class="tbl" width="100%">
	<tr>
		<th>#</th>
		<th>Url</th>
		<th>Defaults</th>
		<th>Constraints</th>
		<th>Handler</th>
	</tr>
@{
	int i = 0;
	
	foreach (RouteBase rr in this.Model.Routes) {
		if (rr is Route) {
			Route r = (Route)rr;
			bool isMatch = matches != null && matches.Any(m => m.Route == r);
			string rAttrs = isMatch ? "style=\"font-weight:bold; color:green;\"" : "";
		<tr @rAttrs.AsHtml()>
			<td align="center">@i</td>
			<td>@r.Url</td>
			<td style="white-space:nowrap">
				@if (r.Defaults != null) {
					foreach (var kv in r.Defaults) {
						@kv.Key<text> = </text>@kv.Value<br/>
					}
				}
			</td>
			<td>
				@if (r.Constraints != null) {
					foreach (var kv in r.Constraints) {
						@kv.Key<text> = </text>@kv.Value<br/>
					}
				}
			</td>
			<td>@r.RouteHandler.GetType().Name</td>
		</tr>
		
		}
		i++;
	}
}
</table>